// GFLeakDlg.h : header file
//

#pragma once
#include "SaveHelper.h"
#include "ReadHelper.h"
#include "WinDebugMonitor.h"
#include <vector>
#include <map>

// CGFLeakDlg dialog
class CGFLeakDlg : public CDialog
{
// Construction
public:
	CGFLeakDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_GFLEAK_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnBnClickedAttch();
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnListSelChange();

private:
	DWORD	GetHookProcId();
	void	SetHook(DWORD dwProcId);
	void	ErrMsg(LPCTSTR lpszText);
	bool	AdjustProcessTokenPrivilege();
	CString	MultiByteToCString(LPCH lpchStr);
	void	EndRecord();

	void	ProecssData();
	void	GetLeakInfo();
	void	ParseRecordFile(CString strFilePath);

	void	InitFileMapping();
	void	UninitFileMapping();

private:
	HANDLE		m_hFileMapping;
	PBYTE		m_pData;
	DWORD		m_dwCurPos;
	DWORD		m_dwProcId;

	CListBox	m_oListBox;
	CEdit		m_oDetailEdit;

	std::map<DWORD, CString>			m_mapFuncName;
	std::map<DWORD, CString>			m_mapCtrlName;
	std::vector<DWORD>					m_vctLeakAddr;
	std::map<DWORD, std::vector<DWORD>>	m_mapVctOffset;

	CSaveHelper			m_oSaveHelper;
	CReadHelper			m_oReadHelper;
	CWinDebugMonitor	m_oDebugMonitor;
public:
	afx_msg void OnBnClickedAnalysis();
	afx_msg void OnBnClickedOpen();
};
